from network import *
import sys,urllib.parse ,os

if __name__ == '__main__':
    try:
        artistName=sys.argv[1]
    except:
        artistName='paramore'
    try:
        path=sys.argv[2]
    except:
        path='./artistArt'
    try:
        howMany=int(sys.argv[3])
    except:
        howMany=5
    
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            print('wrong path')
            sys.exit('Exiting')
    
    req=httpLink('http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist='+urllib.parse.quote(artistName)+'&api_key=b25b959554ed76058ac220b7b2e0a026&limit='+str(howMany))
    print(req.reason)
    if req != 'false':
        dom=req.read()
        dom = xml.dom.minidom.parseString(dom)
        handleImages(dom,path,artistName)
    
